package a20_twoDimensionalArray;

/**
 * @Author quan
 * @Description 二维数组求和
 * @Date 2023/2/3 12:55
 */
/*求每个季度的营业额和总营业额
1: 77,33,88
2: 12,56,89
3: 36,74,94*/
public class TestDemo {
    public static void main(String[] args) {
        //定义一个二维数组
        int[][] yearArr = {
                {77,33,88},
                {12,56,89},
                {36,74,94}
        };

        int allSum = 0;
        //求二维数组中的一维数组：每个季度
        for (int i = 0; i < yearArr.length; i++) {
            int[] monthArr = yearArr[i];
            int sum = getSum(monthArr);
            //求整年的营业额
            allSum += sum;
            System.out.println(sum);
        }
        System.out.println(allSum);
    }
    //求每个季度的营业额的和
    public static int getSum(int[] arr){
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum+=arr[i];
        }
        return sum;
    }

}
